import { HttpSrv } from 'lfun-bg-comp';
import { PageParams, PageResult, Result } from '..';

export interface TransferOut {
  current_district_province_id?: number;
  current_district_city_id?: number;
  current_district_area_id?: number;
  current_region_province_id?: number;
  current_region_city_id?: number;
  current_region_area_id?: number;
  current_unit_name?: string;
  transfer_out_date?: string;
  transfer_reason?: string;
  teacher_id?: any;
}
export interface SearchTransferParams {
  teacher_name?: string;
  teacher_number?: string;
  teacher_id_type?: string;
  teacher_id_number?: string;
  teacher_gender?: string;
  original_region_area_id?: string;
  original_district_area_id?: string;
  original_unit?: string;
  current_unit_name?: string;
  current_unit_id?: any;
  current_region_area_id?: string;
  approval_name?: string;
  approval_status?: string;
  operation_time?: string;
  approval_time?: string;
}

export interface TransferRes {
  current_district_province_id?: number;
  current_district_city_id?: number;
  current_district_area_id?: number;
  current_region_province_id?: number;
  current_region_city_id?: number;
  current_region_area_id?: number;
  current_unit_name?: string;
  current_unit_id?: any;
  transfer_in_date?: string;
  transfer_reason?: string;
  teacher_name?: string;
  teacher_number?: string;
  teacher_id_type?: string;
  teacher_id_number?: string;
  teacher_gender?: string;
  original_unit?: string;
  approval_name?: string;
  approval_status?: string;
  operation_time?: string;
  approval_time?: string;
}

// 调出
export const createTransferOut = (params: TransferOut): Result<TransferOut> =>
  HttpSrv().post('/school/v1/teacher-transaction/transfer-out-details', params);

export const searchTransferOutLaunch = (params: PageParams & SearchTransferParams): Result<PageResult<TransferRes>> =>
  HttpSrv().get('/school/v1/teacher-transaction/transfer-out-launch', { params });

export const searchTransferOutApproval = (params: PageParams & SearchTransferParams): Result<PageResult<TransferRes>> =>
  HttpSrv().get('/school/v1/teacher-transaction/transfer-out-approval', { params });

// 撤回
export const transferRevoked = (process_instance_id: any, teacher_id: any) =>
  HttpSrv().patch('/school/v1/teacher-transaction/transfer-revoked', { process_instance_id, teacher_id });

export interface GetTransferTeacherParams {
  teacher_name: string;
  teacher_id_type: string;
  teacher_id_number: string;
}

export const getTransferTeacher = (params: GetTransferTeacherParams) =>
  HttpSrv().get('/school/v1/teacher-transaction/teacher-transfer', { params });

export interface TransferIn {
  transfer_details: {
    // 调入校信息
    current_region_area_id?: string;
    current_unit_id?: string;
    current_position?: string;
    // 调出校信息
    original_district_province_id?: string;
    original_district_city_id?: string;
    original_district_area_id?: string;
    original_unit?: string;
    transfer_out_date?: string;
    transfer_reason?: string;
    original_position?: string;
    remark?: string;
    teacher_id?: any;
  };
  add_teacher?: {
    teacher_name?: string;
    teacher_id_type?: string;
    teacher_id_number?: string;
    teacher_gender?: string;
    teacher_date_of_birth?: string;
  };
}

export const createTransferIn = (params: TransferIn): Result<TransferIn> =>
  HttpSrv().post('/school/v1/teacher-transaction/transfer-in-details', params);

export const searchTransferInApproval = (params: PageParams & SearchTransferParams): Result<PageResult<TransferRes>> =>
  HttpSrv().get('/school/v1/teacher-transaction/transfer-in-approval', { params });

export const searchTransferInLaunch = (params: PageParams & SearchTransferParams): Result<PageResult<TransferRes>> =>
  HttpSrv().get('/school/v1/teacher-transaction/transfer-in-launch', { params });

// 审核通过
export const transferApproved = (process_instance_id: any, reason: string, teacher_id: any) =>
  HttpSrv().patch('/school/v1/teacher-transaction/transfer-approved', { process_instance_id, reason, teacher_id });

// 审核拒绝
export const transferRejected = (process_instance_id: any, reason: string, teacher_id: any) =>
  HttpSrv().patch('/school/v1/teacher-transaction/transfer-rejected', {
    params: { process_instance_id, reason, teacher_id },
  });

// 全部
export const getTransferTeacherList = (teacher_id: any): Result<Array<TransferRes>> =>
  HttpSrv().get('/school/v1/teacher-transaction/transfer-details-all', { params: { teacher_id } });
